package com.amsp.oa.oademo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.amsp.oa.oademo.entity.InterviewNotice;
import com.amsp.oa.oademo.service.InterviewNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "面试通知书管理")
@RestController
@RequestMapping("/api/interview-notice")
@RequiredArgsConstructor
public class InterviewNoticeController {

    private final InterviewNoticeService interviewNoticeService;

    @ApiOperation("分页查询面试通知书")
    @GetMapping("/page")
    public Page<InterviewNotice> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String companyName,
            @RequestParam(required = false) String candidateName) {

        LambdaQueryWrapper<InterviewNotice> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(companyName)) {
            queryWrapper.like(InterviewNotice::getCompanyName, companyName);
        }
        if (StringUtils.isNotBlank(candidateName)) {
            queryWrapper.like(InterviewNotice::getCandidateName, candidateName);
        }
        queryWrapper
                .orderByDesc(InterviewNotice::getCreateTime);

        return interviewNoticeService.page(new Page<>(current, size), queryWrapper);
    }

    @ApiOperation("获取面试通知书详情")
    @GetMapping("/{id}")
    public InterviewNotice getById(@PathVariable Long id) {
        return interviewNoticeService.getById(id);
    }

    @ApiOperation("保存或更新面试通知书")
    @PostMapping("/save")
    public boolean saveOrUpdate(@RequestBody InterviewNotice interviewNotice) {
        return interviewNoticeService.saveOrUpdate(interviewNotice);
    }

    @ApiOperation("删除面试通知书")
    @DeleteMapping("/{id}")
    public boolean removeById(@PathVariable Long id) {
        return interviewNoticeService.removeById(id);
    }

    @ApiOperation("批量删除面试通知书")
    @DeleteMapping("/batch")
    public boolean removeBatchByIds(@RequestBody List<Long> ids) {
        return interviewNoticeService.removeBatchByIds(ids);
    }
}